//
//  GTDeleteCellView.m
//  iOSApp01
//
//  Created by yxh on 2020/4/30.
//  Copyright © 2020 yxh. All rights reserved.
//

#import "GTDeleteCellView.h"

@interface GTDeleteCellView()

@property(nonatomic,strong,readwrite) UIView *backgroundView;
@property(nonatomic,strong,readwrite) UIButton  *deleteButton;

@end

@implementation GTDeleteCellView

- (instancetype) initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self addSubview:({
            _backgroundView = [[UIView alloc] initWithFrame:self.bounds];
            _backgroundView.backgroundColor = [UIColor blackColor];
            _backgroundView.alpha = 0.5;
            [_backgroundView addGestureRecognizer:({
                UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissDeleteView)];
                tapG;
            })];
            _backgroundView;
        })];
        
        [self addSubview:({
            _deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 500, 200,  200)];
            [_deleteButton addTarget:self action:@selector(_clickButton) forControlEvents:UIControlEventTouchUpInside];
            _deleteButton.backgroundColor = [UIColor blueColor];
            _deleteButton;
        })];
    }
    return self;
}

-(void) showDeleteView{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    //        [[[UIApplication sharedApplication] windows] objectAtIndex:0];
//    [UIView animateWithDuration:1.f animations:^{
//        self.deleteButton.frame = CGRectMake((self.bounds.size.width -200)/2, (self.bounds.size.height -200)/2, 200,  200);
//    }];
    
    [UIView animateWithDuration:1.f delay:0.f usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
         self.deleteButton.frame = CGRectMake((self.bounds.size.width -200)/2, (self.bounds.size.height -200)/2, 200,  200);
    } completion:^(BOOL finished){
        
    }];
    
}


-(void) dismissDeleteView{
    [self removeFromSuperview];
}

- (void) _clickButton{
    [self removeFromSuperview];
}

@end
